import 'package:flutter/material.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/setting/children/address/add_address/controller/add_address_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/extension/widget_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/button_common.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:flutterproject/widget/text/text_field_common.dart';
import 'package:get/get.dart';

class AddAddressPage extends BaseState<AddAddressController> {
  @override
  AddAddressController initController() => AddAddressController();

  @override
  Widget initView(BuildContext context) {
    return Container(
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          AppBarCommon(
            title: "编辑收货地址",
            rightWidget: TextCommon(
              "删除",
              size: 24.sp,
            ).addClickEvent(() {controller.deleteAddress();}),
          ),
          23.heightBox,
          Container(
            width: Get.width,
            padding: MarginPaddingUtil.symmetric(horizontal: 37),
            margin: MarginPaddingUtil.symmetric(horizontal: 20),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.sp),
            ),
            child: Column(
              children: [
                _buildItem(
                    title: '收货人',
                    hint: '请输入收货人姓名',
                    controller: controller.nameController),
                _buildItem(
                    title: '手机号码',
                    hint: '填写收货人手机号',
                    controller: controller.phoneController),
                _buildItem(
                    title: '所在地区',
                    hint: '省市区县，乡镇等',
                    controller: controller.areaController),
                _buildItem(
                    title: '详细地址',
                    hint: '街道，楼牌号等',
                    controller: controller.streetController),
                30.heightBox,
                Row(
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        TextCommon(
                          "设置默认地址",
                          size: 24.sp,
                        ),
                        12.heightBox,
                        TextCommon(
                          "提醒：下单会优先使用该地址",
                          size: 20.sp,
                          color: Color(0xFF707070),
                        ),
                      ],
                    ),
                    Spacer(),
                    ImageCommon(
                      "/image/${(controller.bean?.top == 1) ? "switch_on" : "switch_off"}",
                      width: 76.width,
                      height: 35.height,
                      fit: BoxFit.contain,
                    ).addClickEvent(() => controller.changeTop())
                  ],
                ),
                38.heightBox
              ],
            ),
          ),
          Spacer(),
          Container(
            width: Get.width,
            color: Colors.white,
            padding: MarginPaddingUtil.symmetric(vertical: 22, horizontal: 200),
            child: ButtonCommon(
              text: "保存",
              onTap: () => controller.updateAddress(),
              fontSize: 32.sp,
              fontColor: Colors.white,
              color: Color(0xFFEDC88B),
              borderRadios: 50,
              padding: MarginPaddingUtil.only(top: 25, bottom: 29),
            ),
          )
        ],
      ),
    );
  }

  Widget _buildItem(
      {required String title,
      required String hint,
      required TextEditingController controller}) {
    return Column(
      children: [
        42.heightBox,
        Row(
          children: [
            SizedBox(
              width: 130.width,
              child: TextCommon(
                title,
                size: 28.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
            70.widthBox,
            Expanded(
              child: TextFieldCommon(
                controller: controller,
                height: 35.height,
                hintText: hint,
                hintSize: 28.sp,
                hintColor: Color(0xFFFF6F7277).withOpacity(0.5),
                textColor: Colors.black,
                enabledBorderColor: Color(0xFFE4E9EB),
                focusedBorderColor: Color(0xFFE4E9EB),
                inputBorder: InputBorder.none,
                onChanged: (value) {},
              ),
            )
          ],
        ),
        25.heightBox,
        Divider(
          color: Color(0xFFE7E7E7),
          height: 1,
        )
      ],
    );
  }
}
